import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-15
 * Time: 8:23
 */
public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphor=new Semaphore(4);
      semaphor.acquire();
        System.out.println("P 操作");
        semaphor.acquire();
        System.out.println("P 操作");
        semaphor.acquire();
        System.out.println("P 操作");
        semaphor.acquire();

        System.out.println("P 操作");
        Thread t=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                semaphor.release();
                System.out.println("释放资源");
            }
        });
        t.start();
        semaphor.acquire();
        System.out.println("P 操作");

    }
}
